package com.tepusoft.wx.controller;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.jfinal.plugin.ehcache.CacheInterceptor;
import com.jfinal.plugin.ehcache.CacheKit;
import com.jfinal.plugin.ehcache.CacheName;
import com.tepusoft.wx.model.User;

import java.util.List;

/**
 * User: GIE
 * Date: 2015/12/15
 * description：
 */
public class HelloController extends Controller {
	public void index() {
		PropKit.use("log4j.properties");
		String result = PropKit.get("log4j.logger.cn.vesung");
		System.out.println(result);
		renderJsp("/index.jsp");
	}

	public void saveUser(){
		User user = getModel(User.class,"user");
		user.save();
		renderText("保存成功");
	}

	public  void saveUserDb(){
		System.out.println(getPara("username"));
		System.out.println(getPara(2));
		Record record = new Record().set("username",getPara("username")).set("password",getPara("password"));
		Db.save("user",record);
		renderText("保存成功");
	}

	@Before({Tx.class,LoginValidtor.class})
	public void saveTx(){
		getModel(User.class).save();
		renderText("保存成功");
	}

//	@Before(CacheInterceptor.class)
//	@CacheName("sampleCache2")
	public void listUser(){
		List<User> list = User.dao.findByCache("sampleCache2","1","select * from user");
		renderJson(list);
	}

	public void getCache(){
		List<User> list = CacheKit.get("sampleCache2", "1");
		renderJson(list);
	}

}